<?php
/**
* controllerBase, base class which all controllers extend
*
* every module contains a controller file and an admin file, these files contain
* a controller class which extends this one.  The controller base class sets up 
* variables and methods that should be common to all controller files.  namely the 
* to string magic method which allows for consistent output from modules.
*@author		wil hamilton <wil.hamilton@gmail.com>
*@license		bsd
*@version		0.5
*@package		core
* @todo 		fix up the toString method to allow for better skinning and templates (ultimately better implementation of MVC), also add better documentation and comments
 */
 

class controllerBase {
	
	/**
	 * the $method property defines the default method which is called by the controller if
	 * no other method is specifed
	 *
	 * @var array
	 */
	public $method = array('index');
	
	/**
	 * the $content property sets up a place where all page content can be written to
	 *
	 * @var string
	 */
	public $content = '';
	
	/**
	 * the $title property is where a controller can write the page title to be displayed to
	 *
	 * @var string
	 */
	public $title = '';
	
	/**
	 * the $display property is whether or not the default skinning method will be used
	 *
	 * @var bool
	 */
	public $display = true;
	public $header = '';
	
	/**
	 * the __toString function converts a controller to a string, to allow it to be displayed
	 */
	function __toString ()
	{
		global $headers;
		
		//if  there is no content yet, get whatever has been echoed
		if($this->content == '')
		{
			$this->content = '';
			$this->content .= ob_get_clean();
		}
		
		#if we using the default display method use it, if not, just give the content
		if($this->display)
		{			
			skin::header($this->title);
			skin::menu($this->header);
			echo $this->content;
			skin::footer();
			return '' . ob_get_clean();
		}
		else
		{
			return '' . $this->content;
		}
		
	}

}